/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { DefaultSyncTask, hvigorCore, Module } from '@ohos/hvigor';
import { defaultModelRegistry } from '@ohos/hvigor';

import { TaskNames } from '../common/task-names.js';

import { OhosModuleModelBean } from './ide/ohos-module-model-bean.js';
import CommonTask = TaskNames.CommonTask;

/**
 * Module级别的Sync任务
 *
 * @since 2022/2/19
 */
export class SyncModule extends DefaultSyncTask {
  private readonly isFaMode;

  constructor(module: Module, taskName: string, isFaMode: boolean) {
    super(module, taskName);
    this.isFaMode = isFaMode;
    hvigorCore.versionChanged() && this.dependsOn(CommonTask.CLEAN.name);
  }

  registryAction = (): Function => {
    return () => {
      const ohosModuleModelBean = new OhosModuleModelBean(this.node as Module, this.isFaMode);
      defaultModelRegistry.registry(ohosModuleModelBean);
    };
  };
}
